import { useState, useCallback } from 'react';
import { search } from '@/api';

export default function useHome() {
  //企业列表
  const [companyData, setCompanyData] = useState([]);
  const [houseData, setHouseData] = useState([]);
  const getData = useCallback(
    async (params: {
      type: number;
      name: string;
      pageNo: number;
      pageSize: number;
    }) => {
      const res = await search.getData(params);
      if (res && res.data) {
        params.type ? setHouseData(res.data) : setCompanyData(res.data);
      } else {
        setCompanyData([]);
      }
    },
    [],
  );

  return {
    companyData,
    getData,
    houseData,
  };
}
